package com.whale;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.whale.activity.WhaleBaseActivity;
import com.whale.util.TimeUtil;

/**
 * @author lzk
 * 
 */
public class ReplyActivity extends WhaleBaseActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.reply);
		ListView listView = (ListView) findViewById(R.id.replyListView);
		List<Reply> replyList = new ArrayList<Reply>();
		replyList.add(new Reply(1l, "tom", "是不错", new Date()));
		replyList.add(new Reply(2l, "jack", "不错", new Date()));
		replyList.add(new Reply(3l, "david", "ok", new Date()));
		listView.setAdapter(new ReplyListAdapter(replyList));
	}

	class ReplyListAdapter extends BaseAdapter {
		private List<Reply> replyList;

		public ReplyListAdapter(List<Reply> replyList) {
			super();
			this.replyList = replyList;
		}

		@Override
		public int getCount() {
			return replyList.size();
		}

		@Override
		public Object getItem(int position) {
			return replyList.get(position);
		}

		@Override
		public long getItemId(int position) {
			return replyList.get(position).trendId;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			Reply reply = replyList.get(position);
			LayoutInflater inflate = LayoutInflater.from(ReplyActivity.this);
			View view = inflate.inflate(R.layout.replyitem, null);
			ImageView replyImage = (ImageView) view
					.findViewById(R.id.replyImage);
			replyImage.setImageResource(R.drawable.icon);
			TextView replyName = (TextView) view.findViewById(R.id.replyName);
			replyName.setText(reply.name);
			TextView replyTime = (TextView) view.findViewById(R.id.replyTime);
			replyTime.setText(TimeUtil.timsDiff(reply.time));
			TextView replyContent = (TextView) view
					.findViewById(R.id.replyContent);
			replyContent.setText(reply.content);
			return view;
		}

	}
}
